<?php

$this->stylesheet()->controller();

$this->dojo()->addStyleSheet($this->dojo()->getCdnBase() . $this->dojo()->getCdnVersion() . '/dojox/grid/resources/tundraGrid.css')
             ->requireModule('core.grid.Scaffold')
             ->onLoadCaptureStart();
?>
function(){
    var cells = [
    {
        name: "<?php $this->_e('Alias')?>",
        field: "alias",
        width:'100px'
    },
    {
        name: "<?php $this->_e('Subject')?>",
        field: "subject",
        width:'120px'
    },
    {
        name: "<?php $this->_e('Body')?>",
        field: "bodyHtml",
        width:'auto',
        formatter: html2textFormatter
    }
    ];

    var datagrid = new core.grid.Scaffold(cells,
                                          'gridContainer',
                                          '<?php echo $this->url();?>',
                                          true,
                                          false,
                                          {name:'Send',
                                          title:'Send',
                                          action:'sendAction(this)',
                                          width:'25px',
                                          class:'asdas'});
    function html2textFormatter(data)
    {
        //by default grid replaces itself < to &lt;
        //so we need to remove all between &lt; and >
        var text = data.replace(/\&lt;(.*?)\>/g, '');

        // cut to long text and add '...'
        if (text.length > <?php echo $this->aOptions['maxLength'];?>) {
            text = text.substr(0, <?php echo $this->aOptions['maxLength'];?>)+'...';
        }
        return text;
    }
    sendAction = function(node){
      //var item = dijit.byId('datagrid').getItem(node.name);
        var item = dijit.byId('datagrid').store._getItemByIdentity(node.name);
        document.location = '<?php echo $this->url(array('action' => 'send'));?>/alias/'+item.alias;
    }

}
<?php $this->dojo()->onLoadCaptureEnd(); ?>
<div class="gridControl">
<?php
    echo $this->comboBox('grid-field',
                         'alias',
                         array('jsid' => 'grid-field', 'autocomplete' => false),
                         array(),
                         array('alias'      => $this->__('Alias'),
                               'subject'    => $this->__('Subject'),
                              )
                        );
    echo $this->validationTextBox('grid-filter',
                                  '*',
                                  array('jsid'      => 'grid-filter',
                                        'regExp'    => '[\S\s]+',
                                        'required'  => 'true'),
                                  array('style'     => 'padding:2px 1px 1px')
                                  );

    echo $this->button('grid-search',
                       $this->__('Filter'),
                       array('jsid'      => 'grid-search',
                             'baseClass' => 'gridButton'));
    echo $this->button('grid-undo',
                       $this->__('Undo'),
                       array('jsid'      => 'grid-undo',
                             'baseClass' => 'gridButton'));
?>
</div>

<div class="gridContainer" id="gridContainer" style="height:300px;"></div>